package com.recommend.recommendkeyword.controller;

import com.recommend.recommendkeyword.common.CommonResponse;
import com.recommend.recommendkeyword.entity.Keywords;
import com.recommend.recommendkeyword.entity.RecommendKeyword;
import com.recommend.recommendkeyword.service.RankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ranking")
public class RankingController {
    @Autowired
    RankingService rankingService;
    @GetMapping("/system")
    public CommonResponse<List<Keywords>> systemRanking(){
        List<Keywords> keywordsList = rankingService.systemRanking();
        if(keywordsList == null || keywordsList.isEmpty()){
            return CommonResponse.createForError("查看排行榜失败");
        }
        return CommonResponse.createForSuccess("SUCCESS", keywordsList);
    }

    @GetMapping("/user")
    public CommonResponse<List<Keywords>> userRanking(@RequestParam int userId){
        List<Keywords> keywordsList = rankingService.userRanking(userId);
        if(keywordsList == null || keywordsList.isEmpty()){
            return CommonResponse.createForError("查看排行榜失败");
        }
        return CommonResponse.createForSuccess("SUCCESS", keywordsList);
    }
}
